package com.yiwei.zhh.adapter;

import android.content.ClipboardManager;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.yiwei.zhh.R;
import com.yiwei.zhh.adapter.base.BaseLViewHolder;
import com.yiwei.zhh.adapter.base.BaseListAdapter;
import com.yiwei.zhh.model.OfflinePaymentModel;
import com.yiwei.zhh.util.ToastUtil;

import java.util.List;

/**
 * 线下支付适配器
 */
public class OfflinePaymentAdapterNew extends BaseListAdapter<OfflinePaymentModel.Info> {

    private LayoutInflater inflater;
    private List<OfflinePaymentModel.Info> list;
    private Context context;

    public OfflinePaymentAdapterNew(Context context, List<OfflinePaymentModel.Info> list) {
        super(context,list);
        this.list = list;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public View bindView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.offline_payment_items, null);
        }
        ( (TextView) BaseLViewHolder.get(convertView,R.id.name)).setText(list.get(position).getName());
        ( (TextView) BaseLViewHolder.get(convertView,R.id.value)).setText(list.get(position).getValue());
        if (list.get(position).getName().equals(context.getString(R.string.payment_account))) {
            BaseLViewHolder.get(convertView,R.id.copy).setVisibility(View.VISIBLE);
            BaseLViewHolder.get(convertView,R.id.copy).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    copy(list.get(position).getValue());
                }
            });
        }

        return convertView;
    }


    void copy(String text) {
        ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        cm.setText(text);
        ToastUtil.makeText(context, context.getString(R.string.copy_success), Toast.LENGTH_SHORT).show();
    }

}


